package cn.iocoder.yudao.module.bpm.utils;

import org.flowable.bpmn.model.ExtensionElement;
import org.flowable.bpmn.model.FlowElement;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BpmUtils {

  /**
   * 获取节点对应的扩展
   * @param flowNode
   * @return
   */
  public static Map<String,String> getTaskExtend(FlowElement flowNode) {
    //返回参数
    Map<String,String> extendMap = new HashMap<>() ;
    if(flowNode != null) {
      //遍历扩展数据
      Map<String, List<ExtensionElement>> extensionElements = flowNode.getExtensionElements();
      extensionElements.forEach((key,value) -> {
        value.stream().forEach((element) -> {
          element.getChildElements().forEach((key1,value1) -> {
            value1.stream().forEach((element1) -> {
              try {
                extendMap.put(element1.getAttributes().get("name").get(0).getValue(), element1.getAttributes().get("value").get(0).getValue());
              }catch (Exception e) {}
            });
          });
        });
      });
    }
    return extendMap ;
  }
}
